<template>
	<view class="u-page">
		<u-notice-bar :text="tips"></u-notice-bar>
		<u-subsection mode="subsection" :list="tabs" :current="cureentIndex" @change="getCureentTabs"></u-subsection>
		<u-gap height="10" bgColor="#f1f1f1"></u-gap>
		<u-list v-show='!noOrder' @scrolltolower="scrolltolower">
			<u-list-item v-for="(item, index) in orderList" :key="index">
				<u--image :showLoading="true" :src="item.orderGoodsImage" width="100px" height="130px"
					@click="sureOrder">
				</u--image>
				<view style="right: 10px;position: absolute;;margin-top: 10px;">
					<u--text :text="'订单号为：'+item.orderId"></u--text>
					<u--text :text="'商品名称为：'+item.orderGoodsName"></u--text>
					<u--text :text="'商品价格为：¥'+item.orderGoodsPrice"></u--text>
					<u--text :text="'状态：'+item.orderStatus"></u--text>
					<u--text :text="'订单创建时间为：'+item.orderCreateTime"></u--text>
				</view>
				<u-divider></u-divider>
			</u-list-item>
		</u-list>
		<u-empty mode="order" v-show="noOrder" icon="http://cdn.uviewui.com/uview/empty/car.png">
		</u-empty>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				noOrder: false,
				status: '待付款',
				tabs: ['待付款', '已付款', '待评价'],
				orderList: [],
				tips: '点击商品图片进行付款',
				cureentIndex: 0,
			}


		},
		onShow() {
			let name = '';
			uni.getStorage({
				key: 'user_name',
				success: function(res) {
					name = res.data;
				}
			})
			uni.$u.http.get('/serviceUser/order/getOrdersByNameAndStatus', {
				params: {
					name: name,
					status: this.status
				},
			}).then(res => {
				console.log(res == null);
				if (res.list == null || res.list.length == 0 || res == null || res.length == 0) {
					this.orderList = null;
					this.noOrder = true;
				} else this.orderList = res.list
			}).catch((error) => {
				console.log(error);
			})
		},
		onLoad() {
			let name = '';
			uni.getStorage({
				key: 'user_name',
				success: function(res) {
					name = res.data;
				}
			})
			uni.$u.http.get('/serviceUser/order/getOrdersByNameAndStatus', {
				params: {
					name: name,
					status: this.status
				},
			}).then(res => {
				console.log(res);
				console.log(res == null);
				if (res.list == null || res.list.length == 0 || res == null || res.length == 0) {
					this.orderList = null;
					this.noOrder = true;
				} else {
					this.orderList = res.list;
					this.noOrder = false
				}
			}).catch((error) => {
				console.log(error);
			})

		},
		methods: {
			sureOrder() {
				uni.$u.toast("暂未开发")
			},
			getCureentTabs(index) {
				this.cureentIndex = index
				if (index == 0) {
					this.status = '待付款'
				} else if (index == 1) {
					this.status = '已付款'
				} else if (index == 2) {
					this.status = '待评价'
				}
				let name = '';
				uni.getStorage({
					key: 'user_name',
					success: function(res) {
						name = res.data;
					}
				})

				uni.$u.http.get('/serviceUser/order/getOrdersByNameAndStatus', {
					params: {
						name: name,
						status: this.status
					},
				}).then(res => {
					console.log(res);
					console.log(res);
					console.log(res == null);
					if (res.list == null || res.list.length == 0 || res == null || res.length == 0) {
						this.orderList = null;
						this.noOrder = true;
					} else {
						this.orderList = res.list;
						this.noOrder = false
					}
				}).catch((error) => {
					console.log(error);
				})
			}
		}
	}
</script>

<style>

</style>
